import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 业务联系人
class HttpContactService {
  /// 联系人列表
  static Future<Response> contactList(int page) {
    return BaseConfig.httpBase.get('/api/contacts', {'page': page});
  }

  /// 创建联系人
  static Future<Response> createContact({
    String name,
    Map a,
    Map b,
    String email,
    String website,
    int is_taxable,
    int enable_address,
    String address_country,
    String address_city,
    String address_postal_code,
    String address_line_1,
    String address_line_2,
    String address_unit,
    int is_favorite,
    int is_client,
    int is_supplier,
    String country_code,
    String phone_number,
  }) {
    return BaseConfig.httpBase.postJson('/api/contacts', {
      "name": name,
      "0": a ?? {},
      "1": b ?? {},
      "email": email,
      "website": website,
      "is_taxable": is_taxable,
      "enable_address": enable_address,
      "address_country": address_country,
      "address_city": address_city,
      "address_postal_code": address_postal_code,
      "address_line_1": address_line_1,
      "address_line_2": address_line_2,
      "address_unit": address_unit,
      "is_favorite": is_favorite,
      "is_client": is_client,
      "is_supplier": is_supplier,
      "country_code": country_code,
      "phone_number": phone_number
    });
  }

  /// 显示联系人
  static Future<Response> showContact(int contact) {
    return BaseConfig.httpBase.get('/api/contacts/$contact', {'id': contact});
  }

  /// 更新联系人
  static Future<Response> updateContact(
    int contactId, {
    String name,
    Map a,
    Map b,
    String email,
    String website,
    int is_taxable,
    int enable_address,
    String address_country,
    String address_city,
    String address_postal_code,
    String address_line_1,
    String address_line_2,
    String address_unit,
    int is_favorite,
    int is_client,
    int is_supplier,
    String country_code,
    String phone_number,
  }) {
    return BaseConfig.httpBase.putJson('/api/contacts/$contactId', {
      "name": name,
      "0": a ?? {},
      "1": b ?? {},
      "email": email,
      "website": website,
      "is_taxable": is_taxable,
      "enable_address": enable_address,
      "address_country": address_country,
      "address_city": address_city,
      "address_postal_code": address_postal_code,
      "address_line_1": address_line_1,
      "address_line_2": address_line_2,
      "address_unit": address_unit,
      "is_favorite": is_favorite,
      "is_client": is_client,
      "is_supplier": is_supplier,
      "country_code": country_code,
      "phone_number": phone_number
    });
  }

  /// 删除联系人
  static Future<Response> deleteContact(int contactId) {
    return BaseConfig.httpBase.deleteJson('/api/contacts/$contactId', {});
  }

  /// 员工列表
  static Future<Response> employeesDots() {
    return BaseConfig.httpBase.get('/api/employees/dots', {});
  }
}
